<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="../../css/weui.min.css" />
    <link rel="stylesheet" type="text/css" href="../../css/jquery-weui.min.css" />
    <link rel="stylesheet" type="text/css" href="../../css/index.css" />
    <link rel="stylesheet" type="text/css" href="../../css/order.css" />
    <title>签章合同</title>
    <script src="../../js/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/jquery-weui.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/baseConfig.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/jquery.media.js" type="text/javascript" charset="utf-8"></script>
    <script src=" http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
</head>
<style type="text/css">
    .weui-uploader__file_status:before {
        background-color: rgba(255, 255, 255, 0);
    }
</style>

<body>
    <!--<div id="header">
			<div class="header-title" style="position: fixed;top: 0;">
				<img src="../../img/left.png" class="left" />
				<span>签章合同</span>
			</div>
		</div>-->
    <div class="invoice_warp" style="display: none;margin-top: 0;">
        <div class="weui-cells weui-cells_form">
            <form method="post" id="form1" action="##" enctype="multipart/form-data">
                <div class="weui-cell" style="padding: 0;">
                    <div class="weui-cell__bd">
                        <div class="weui-uploader__bd">
                            <ul class="weui-uploader__files">

                            </ul>
                            <div class="weui-uploader__input-box">
                                <input id="uploaderInput" name="file" class="weui-uploader__input js_file" type="file" accept="image/*">
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>

        <div class="demos-content-padded">
            <a href="javascript:;" class="weui-btn weui-btn_primary">上传合同</a>
        </div>
    </div>
    <div class="imgWarp" style="display: none;margin-top: 0;">
        <!--<img src="../../img/photo.png"/>-->
    </div>
    <div class="weui-gallery" style="display: none">
        <span class="weui-gallery__img"></span>
    </div>
    <!--<div class="pdf1">
			<a href="">下载pdf文件</a>
		</div>-->
</body>
<script type="text/javascript">
    $(document).ready(function() {
        baseConfig.historyBack()
        var status = baseConfig.GetQueryString("status")
        $.ajax({
            type: "get",
            url: baseConfig.localHttp + "weChatApi/fgclient/getSignContract",
            async: false,
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            data: {
                clientId: baseConfig.login(),
                orderNo: baseConfig.GetQueryString("orderNo")
            },
            success: function(data) {
                $.hideLoading();
                console.log(data)
                if (status == 1) {
                    $(".invoice_warp").hide()
                    $(".imgWarp").show()
                    if (data.code == 100) {
                        if (!data.content.pdfUrl) {
                            var $img = "";
                            for (var i = 0; i < data.content.picList.length; i++) {
                                $img += "<img src=" + baseConfig.imglocalHttp + data.content.picList[i] + ">"
                            }
                            $(".imgWarp").append($img)
                        } else {
                            window.location.href = baseConfig.imglocalHttp + data.content.pdfUrl
                        }
                    } else {
                        $.toast("暂无数据", "cancel");
                    }

                } else {

                    if (!data.content.pdfUrl) {
                        $(".invoice_warp").show()
                        $(".demos-content-padded").show()
                        if (!data.content.picList) {
                            $(".weui-btn_primary").html("上传合同")
                        } else {
                            $(".weui-btn_primary").html("重新上传")
                        }
                        //								var $li = ""
                        //								for(var i = 0; i < data.content.picList.length; i++) {
                        //									$li += "<li class='weui-uploader__file weui-uploader__file_status'  style='background-image:url(" +
                        //									baseConfig.imglocalHttp+data.content.picList[i] + ")'><img src='../../img/delete.png' class='delete'/></li>"							
                        //								}						
                        //								$(".weui-uploader__files").append($li)
                        ////								$(".weui-uploader__input-box").hide()
                        //								$(".weui-uploader__files .delete").on("click",function(){
                        //									$(this).parent().remove()
                        //									$(".weui-uploader__input-box").show()
                        //								})
                        baseConfig.imgUpload()
                    } else {
                        window.location.href = baseConfig.imglocalHttp + data.content.pdfUrl
                    }

                    $(".weui-btn").on("click", function() {
                        $(".weui-uploader__input-box").find("input:last").attr("name", "")
                        var formData = new FormData($("#form1")[0])
                        formData.append("orderNo", baseConfig.GetQueryString("orderNo"));
                        if ($(".weui-uploader__input-box input").length == 1) {
                            $.toptip("请先选择照片", 1200, 'error')
                        } else {
                            $.ajax({
                                type: "post",
                                url: baseConfig.localHttp + "weChatApi/fgclient/uploadClientSignContract",
                                data: formData,
                                contentType: false,
                                processData: false,
                                success: function(data) {
                                    console.log(data)
                                    if (data.code == 100) {
                                        $.toptip("图片上传成功", 1200, 'success')
                                        setTimeout(function() {
                                            location.href = "mine.html"
                                                //												location.href = "uploadExpress.html?orderNo=" + baseConfig.GetQueryString("orderNo")
                                        }, 1200)
                                    } else {

                                    }
                                },
                                error: function() {
                                    $.hideLoading();
                                    $.toast("图片上传失败", "cancel");
                                }
                            })
                        }
                    })
                }
            },
            error: function() {
                $.hideLoading();
                $.toast("请求失败", "cancel");
            }
        })
    })
</script>

</html>